home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15538 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: cpsc.ucalgary.ca!davidt
  2. From: davidt@cpsc.ucalgary.ca (David Taylor)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: H E L P
  5. Date: 5 Apr 1996 22:03:55 GMT
  6. Organization: University of Calgary CPSC
  7. Message-ID: <4k45cb$j5a@linux.cpsc.ucalgary.ca>
  8. References: <N.040296.013047.18@DynamicPPP-185.HIP.CAM.ORG> <Pine.A32.3.91.960402135001.121719B-100000@green.weeg.uiowa.edu> <4js6jh$ndr@solutions.solon.com>
  9. NNTP-Posting-Host: bh.cpsc.ucalgary.ca
  10.  
  11. In article <4js6jh$ndr@solutions.solon.com>,
  12. Peter Seebach <seebs@solutions.solon.com> wrote:
  13. >In article <Pine.A32.3.91.960402135001.121719B-100000@green.weeg.uiowa.edu>,
  14. >The Amorphous Mass  <robinson@blue.weeg.uiowa.edu> wrote:
  15. >>On Tue, 2 Apr 1996 ramrod@cam.org wrote:
  16. >
  17. >>> The part that I am having a hard time with is the part that
  18. >>> whatever number I enter for the age, I'm supposed to get the same number
  19. >>> of happy faces, automatically.  For example If I say I am 45 years old,
  20. >>> then the program should show 45 happy faces.
  21. >
  22. >>  You need a loop.  Look up the for, while, and do while loop constructs  in 
  23. >>your textbook.
  24. >
  25. >This is a bit strong.  You don't *need* a loop.  You just probably want one.
  26. >
  27. >Obviously, if you're assuming age, you would have no more than about 150 ifs
  28. >to test, (assuming humans), and if you just want to do it for 45, it's even
  29. >easier.
  30. >
  31.  
  32. There is also the recursive technique....
  33.  
  34. void print_n_faces (int n) {
  35.     if (n > 0) {
  36.         printf ("\001");
  37.         print_n_faces (n - 1);
  38.     }
  39. }
  40.  
  41. -- 
  42. Andrew Taylor     |email: davidt@cpsc.ucalgary.ca
  43.                   |www:   http://www.cpsc.ucalgary.ca/~davidt
  44.